package com.xh.chat.netty.event;

import com.xh.chat.netty.enums.MsgActionEnum;
import com.xh.chat.netty.dto.DataContentDTO;
import com.xh.chat.netty.annotation.EventProcess;
import com.xh.chat.netty.utils.ChannelUtil;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author wen
 * @apiNote ConnectEventHandler
 * @since 2021-08-09
 */
@Slf4j
@Service
@EventProcess(MsgActionEnum.CONNECT)
public class ConnectEventHandler implements EventHandler {

    @Override
    public void handle(DataContentDTO dataContentDTO, Channel currentChannel) {
        // 	2.1  当websocket 第一次open的时候，初始化channel，把用的channel和userId关联起来
        Long senderId = dataContentDTO.getChatMsgDTO().getSenderId();
        ChannelUtil.put(senderId, currentChannel);
        // 测试
        for (Channel c : ChannelUtil.USER_CHANNEL_GROUP) {
            log.info(c.id().asLongText());
        }
        ChannelUtil.output();
    }

}
